import requests
import lxml.html
etree = lxml.html.etree

def download_pic(pic_url,x,i):
    try:
        response = requests.get(pic_url)
        with open("D:\gitee\\first_test\\first_test\\img\\mv{}{}.jpg".format(i,x),"wb+") as f:
            f.write(response.content)
    except:
        print("download error")
for i in range(1,10):
    url= "https://alpha.wallhaven.cc/toplist?page={}".format(i)
    try:
        response = requests.get(url)
    except:
        print("geturl Error")
    response.encoding='utf-8'
    selctor = etree.HTML(response.content)
    try:
        img_url = selctor.xpath('//main[@id="main"]/div[@id="thumbs"]/section/ul/li/figure/img/@data-src')
    except:
        print("xpath error")
    for x in range(len(img_url)):
        download_pic(img_url[x],x,i)








